package gzx.datalayer.Data.GongDanMgr
{
	import gzx.datalayer.Data.Title;
	
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;

	public class GongdanMgrQuery
	{
		private var remoteObject:RemoteObject
	
		
		public var onReceive_GetGongdanListByUserId:Function;
		public var onReceive_UpdateGongdanRecord:Function;
		public var onReceive_GetUserInfoByUserId:Function;
		public var onReceive_DelwithGongdan:Function;
		public var onReceive_GetAllTask:Function;
		
//		public var onReceive_Add:Function;
//		public var onReceive_Reject:Function;
//		public var onReceive_PaidanContinue:Function;
//		public var onReceive_Paidan:Function;
		public var onErrorFunction:Function;
		
		public function GongdanMgrQuery( )
		{
			remoteObject  = new RemoteObject("fluorine");
			remoteObject.source = "RemoteFlunorineFx.GongdanMgr.GongdanModule";
		
			remoteObject.GetGongdanListByUserId.addEventListener("result",getGongdanListByUserId_ResultHandler);
			
			remoteObject.UpdateGongdanRecord.addEventListener("result",updateGongdanRecord_ResultHandler);
			
			remoteObject.GetUserInfoByUserId.addEventListener("result",getUserInfoByUserId_ResultHandler);
			//DelwithGongdan(GongDanProj proj,int type,int requestDayNums,int status)
			
			remoteObject.DelwithGongdan.addEventListener("result",DelwithGongdan_ResultHandler);
			remoteObject.GetAllTask.addEventListener("result",GetAllTask_ResultHandler);
			
			
//			remoteObject.Paidan.addEventListener("result",paidan_ResultHandler);
//			
//			remoteObject.Reject.addEventListener("result",reject_ResultHandler);
//			remoteObject.PaidanContinue.addEventListener("result",paidanContinue_ResultHandler);
//			
			remoteObject.addEventListener("fault", onFault);
			
			onReceive_GetGongdanListByUserId = null;
			onReceive_GetGongdanListByUserId=null;
			onReceive_UpdateGongdanRecord=null;
			onReceive_GetUserInfoByUserId=null;
			onReceive_DelwithGongdan=null;
			onReceive_GetAllTask=null;
			onErrorFunction = null;
		}
		//    
		//====================
		public function getGongdanListByUserId(userId:String,status:int,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetGongdanListByUserId(userId,status);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function getGongdanListByUserId_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetGongdanListByUserId)
				onReceive_GetGongdanListByUserId(event.result);
		}
		
		//=========================
		
		//====================
		public function updateGongdanRecord(gongdan:GongdanModel,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.UpdateGongdanRecord(gongdan);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function updateGongdanRecord_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_UpdateGongdanRecord)
				onReceive_UpdateGongdanRecord(event.result);
		}
		public function getUserInfoByUserId(userId:String,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetUserInfoByUserId(userId);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function getUserInfoByUserId_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetUserInfoByUserId)
				onReceive_GetUserInfoByUserId(event.result);
		}
		/*
		*type 1:转派  2：打回   3：处理     4：申请延时        5：拒绝申请延时       6： 同意申请延时  
		*/
		
		public function DelwithGongdan(gongdan:GongdanModel, type :int, requestDayNums:int=0 ,responder:IResponder = null):void{
			
			var asyncToken:AsyncToken = remoteObject.DelwithGongdan(gongdan,type,requestDayNums);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		}
		public function DelwithGongdan_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_DelwithGongdan)
				onReceive_DelwithGongdan(event.result);
		}
		
//		public function paidanContinue(currentUser:String,gongdan:GongdanModel,responder:IResponder = null ):void
//		{
//			var asyncToken:AsyncToken = remoteObject.PaidanContinue(currentUser,gongdan);
//			
//			if( responder != null )
//				asyncToken.addResponder(responder);
//		} 
//		public function paidanContinue_ResultHandler(event:ResultEvent):void
//		{
//			if(null != onReceive_PaidanContinue)
//				onReceive_PaidanContinue(event.result);
//		}
//		public function add(gongdan:GongdanModel,responder:IResponder = null ):void
//		{
//			var asyncToken:AsyncToken = remoteObject.Add(gongdan);
//			
//			if( responder != null )
//				asyncToken.addResponder(responder);
//		} 
//		public function add_ResultHandler(event:ResultEvent):void
//		{
//			if(null !=onReceive_Add)
//				onReceive_Add(event.result);
//		}
//		public function reject( currentUser:String,gongdan:GongdanModel,responder:IResponder = null ):void
//		{
//			var asyncToken:AsyncToken = remoteObject.Reject(currentUser,gongdan);
//			
//			if( responder != null )
//				asyncToken.addResponder(responder);
//		} 
//		public function reject_ResultHandler(event:ResultEvent):void
//		{
//			if(null != onReceive_Reject)
//				onReceive_Reject(event.result);
//		}
//		public function paidan( currentUser:String,gongdan:GongdanModel,responder:IResponder = null ):void
//		{
//			var asyncToken:AsyncToken = remoteObject.Paidan(currentUser,gongdan);
//			if( responder != null )
//				asyncToken.addResponder(responder);
//		} 
//		public function paidan_ResultHandler(event:ResultEvent):void
//		{
//			if(null != onReceive_Paidan)
//				onReceive_Paidan(event.result);
//		}
//
//		
		//====================
		public function GetAllTask(param:AllTaskParamItem,responder:IResponder = null ):void
		{
			var asyncToken:AsyncToken = remoteObject.GetAllTask(param);
			
			if( responder != null )
				asyncToken.addResponder(responder);
		} 
		public function GetAllTask_ResultHandler(event:ResultEvent):void
		{
			if(null != onReceive_GetAllTask)
				onReceive_GetAllTask(event.result);
		}
		//=========================
		public function onFault (event:FaultEvent):void
		{
			if(onErrorFunction!=null)
			{
				onErrorFunction();
			}
			else
			{
				Alert.show(event.fault.faultString, "Error");
			}
		}
	}
}